# Author   : zhen.fang
# Time     : 2020/10/11 20:08
# Email    : fangeddie@163.com
import os
import importlib
import yaml

# * 指定环境, setting_${SPECIAL_ENV}.py 必须存在
SPECIAL_ENV = os.environ.get('SPECIAL_ENV')


def get_env(base_url):
    try:
        with open(f"{base_url}/config_{SPECIAL_ENV}.yml") as f:
            config = yaml.load(f, Loader=yaml.FullLoader)
        return config
    except FileNotFoundError as exc:
        raise FileNotFoundError(
            "Couldn't import setting file {}/config_{}.yml, Are you sure it's correct ?".format(base_url, SPECIAL_ENV) +
            " Perhaps, you forget to set SPECIAL_ENV ?"
        ) from exc


def is_main_process():
    # 本地调试时用，可以区分是热加载服务还是真实服务，其它环境无效
    return os.environ.get('RUN_MAIN') == 'true'
